﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Architecture.Logging.Agent.Configuration
{
    public class LoggingConfiguration
    {

        private List<TraceProvider> _providers = new List<TraceProvider>();

        public static LoggingConfiguration Current = new LoggingConfiguration();

        private LoggingConfiguration()
        {
            _providers.Add(new TraceProvider()
            {
                Enabled = true,
                Id = Guid.Parse("7E8AD27F-B271-4EA2-A783-A47BDE29143B"),
                Name = "Microsoft-Windows-IIS-Logging"
            });
        }


        public List<TraceProvider> GetProviders()
        {
            return _providers;
        }

        public TraceProvider FindById(Guid id)
        {
            return _providers.FirstOrDefault(t => t.Id.Equals(id));
        }

        public void AddProvider(TraceProvider provider)
        {
            var existingProvider = _providers.FirstOrDefault(t => t.Id.Equals(provider.Id));

            if (existingProvider != null)
            {
                throw new Exception(String.Format("provider {0} with Id {1} already exist", provider.Name, provider.Id));
            }

            _providers.Add(provider);
        }



    }
}
